package com.zhiyun.yycall;

/**
 * Title: 带选择按钮的对话框
 * Description:一般是带一个肯定和否定的按钮
 * Copyright:Copyright(c) 2011
 * Company:Kingdee
 * 
 * @author tom_liang
 */

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.gzit.utils.StringUtils;

@Deprecated
public class CallbackUUActivity extends Activity implements OnClickListener {

	private TextView content;

	private BroadcastReceiver messageReceiver = new BroadcastReceiver() {

		@Override
		public void onReceive(Context context, Intent intent) {
			Bundle buddle = intent.getExtras();
			String msg = buddle.getString("msg");
			if (!StringUtils.isBlank(msg)) {
				setContent(msg);
			}

		}
	};

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.yycall_popup_window);
		content = (TextView) this.findViewById(R.id.content);

		IntentFilter filter = new IntentFilter();
		filter.addAction(YYCallController.MESSAGE_ACTION);
		registerReceiver(messageReceiver, filter);

		String msg = this.getIntent().getStringExtra("msg");
		this.setContent(msg);

	}

	@Override
	protected void onStop() {
		super.onStop();
		unregisterReceiver(messageReceiver);
	}

	@Override
	protected void onNewIntent(Intent intent) {
		super.onNewIntent(intent);

	}

	private void setContent(String msg) {
		this.content.setText(msg);
	}

	@Override
	public void onClick(View v) {
	}

	/**
	 * 屏蔽返回按钮
	 */
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			return false;
		}
		return super.onKeyDown(keyCode, event);
	}

	public static void sendMsg(Context context, String msg) {

		Intent intent = new Intent();
		intent.putExtra("msg", msg);
		intent.setAction(YYCallController.MESSAGE_ACTION);
		context.sendBroadcast(intent);

	}

	public static void showCallbackUUWindow(Context context, String msg) {

		Intent uuintent = new Intent(context, CallbackUUActivity.class);
		uuintent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		uuintent.putExtra("msg", msg);
		context.startActivity(uuintent);

	}
}
